package com.snoob.bffApi.wConfig.configurer;

import com.snoob.bffApi.wConfig.Intercept.AuthIntercept;
import com.snoob.bffApi.wConfig.Intercept.auth.AuthMethodArgumentResolver;
import com.snoob.bffApi.wConfig.properties.SysProperties;
import com.snoob.bffApi.wConfig.redis.RedissonSingleService;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.List;

/**
 * @描述: TODO WebMvc配置
 * @作者: lixing_java@163.com
 * @日期 2020/2/19 22:23
 */
@Component("baseConfigWebMvcConfig")
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    /**
     * @描述 TODO 拦截器配置
     * @作者 lixing
     * @日期 2020/2/19 22:27
     * @Param [registry]
     */
    @Resource
    private RedissonSingleService<String> redissonSingleServiceStr;
    @Resource
    private SysProperties sysProperties;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 认证拦截器
        registry.addInterceptor(new AuthIntercept(redissonSingleServiceStr, sysProperties)).addPathPatterns("/**");
        // 系统模块拦截器
        //registry.addInterceptor(new SysIntercept()).addPathPatterns("/**").excludePathPatterns("/","/sys/admin/login","/static/**","/index.html");
        // 接口防刷拦截器
        // registry.addInterceptor(new AccessLimitIntercept(redisTemplate)).addPathPatterns("/**").excludePathPatterns("/","/sys/admin/login","/static/**","/index.html");
        // 微信活动.用户进入首页静默授权拦截器
        //registry.addInterceptor(new AuthIntercept(wxProperties)).addPathPatterns("/wx/hkSeckill/index/**");
        // 微信活动.号卡秒杀拦截器
        //registry.addInterceptor(new DrawLimitIntercept(redisTemplate)).addPathPatterns("/wx/hkSeckill/seckill/**");
    }

    /**
     * @描述 TODO 参数解析器
     * @作者 李星
     * @日期 2020/2/20 13:34
     * @Param [resolvers]
     */
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        // 用户登录的参数解析器
        resolvers.add(new AuthMethodArgumentResolver());
    }
}
